package com.ourteam.product.requirement.dao.impl;

import com.ourteam.product.requirement.dao.IProductVersionScopeDAO;
import com.ourteam.product.requirement.dao.ProductVersionScope;
import com.ourteam.product.requirement.dao.ProductVersionScopeDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-05-03 16:45:41
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductVersionScopeDAOJdbcImpl extends AbstractSpringDAO
    implements IProductVersionScopeDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, ProductVersionId, ScopeName, ScopePriority, Status, Remarks,
            ProductVersionName
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.ProductVersionId,
            _DataObjectProperty.ScopeName, _DataObjectProperty.ScopePriority,
            _DataObjectProperty.Status, _DataObjectProperty.Remarks,
            _DataObjectProperty.ProductVersionName
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductVersionScope, ProductVersionScopeDAOQueryBean> daoHelper;

    public AbstractProductVersionScopeDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductVersionScope, ProductVersionScopeDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.product.requirement.dao.IProductVersionDAO.EntityName)
                                .append(" PRODUCT_VERSION ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.product.requirement.dao.IProductVersionDAO.Id,
                    com.ourteam.product.requirement.dao.IProductVersionDAO.EntityName +
                    ".", "PRODUCT_VERSION."));
            relatedJoinSQLBuffer.append(" = ").append(ProductVersionId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductVersionScope
         * @throws Exception
         */
    public boolean checkIsUnique(ProductVersionScope aProductVersionScope)
        throws Exception {
        if (aProductVersionScope == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductVersionScope.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductVersionScope
     * @throws Exception
     */
    public void insert(ProductVersionScope aProductVersionScope)
        throws Exception {
        super.doInsert(aProductVersionScope);
    }

    /**
         * Batch Insert Datas
         * @param aProductVersionScope
         * @throws Exception
         */
    public void batchInsert(ProductVersionScope[] aProductVersionScopes)
        throws Exception {
        super.doBatchInsert(aProductVersionScopes);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductVersionScopeDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(ProductVersionScope aProductVersionScope)
        throws Exception {
        delete(aProductVersionScope.getId());
    }

    /**
     * Update Data Selective
     * @param aProductVersionScope
     * @throws Exception
     */
    public void update(ProductVersionScope aProductVersionScope)
        throws Exception {
        if (aProductVersionScope.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductVersionScope);

        ProductVersionScope tempObj = findById(aProductVersionScope.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductVersionScope, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductVersionScopes[]
     * @throws Exception
     */
    public void batchUpdate(ProductVersionScope[] aProductVersionScopes)
        throws Exception {
        super.doBatchUpdate(aProductVersionScopes);
    }

    /**
         * Update Data By Condictions
         * @param aProductVersionScope
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(ProductVersionScope aProductVersionScope,
        ProductVersionScopeDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aProductVersionScope, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductVersionScopeDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(ProductVersionScope aProductVersionScope)
        throws Exception {
        if (aProductVersionScope.getScopeName() == null) {
            throw new Exception(
                "The ProductVersionScope.scopeName value is not allow NULL");
        }

        if (aProductVersionScope.getStatus() == null) {
            throw new Exception(
                "The ProductVersionScope.status value is not allow NULL");
        }

        if (aProductVersionScope.getRemarks() == null) {
            throw new Exception(
                "The ProductVersionScope.remarks value is not allow NULL");
        }

        if (aProductVersionScope.getProductVersionName() == null) {
            throw new Exception(
                "The ProductVersionScope.productVersionName value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductVersionScope findById(final long id)
        throws Exception {
        ProductVersionScopeDAOQueryBean queryBean = new ProductVersionScopeDAOQueryBean();

        ProductVersionScopeDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductVersionScope[] ProductVersionScopes = query(queryBean);

        if (ProductVersionScopes.length == 0) {
            return null;
        } else {
            return ProductVersionScopes[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductVersionScope[]
         * @throws Exception
         */
    public ProductVersionScope[] query(
        ProductVersionScopeDAOQueryBean queryBean) throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcProductVersionScopeRowMapper());

        return (ProductVersionScope[]) result.toArray(new ProductVersionScope[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductVersionScopeDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(ProductVersionScopeDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(ProductVersionScope[] aProductVersionScopes,
        ProductVersionScopeDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aProductVersionScopes, queryBean);
    }

    public void synchronize(ProductVersionScope[] aProductVersionScopes,
        ProductVersionScopeDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductVersionScope> callBack)
        throws Exception {
        daoHelper.synchronize(aProductVersionScopes, queryBean, callBack);
    }

    public static class JdbcProductVersionScopeRowMapper implements RowMapper<ProductVersionScope> {
        public ProductVersionScope mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            ProductVersionScope object = new ProductVersionScope();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object productVersionId = null;

                productVersionId = resultSet.getObject(columnIndex++);

                object.setProductVersionIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (productVersionId != null) {
                    setBeanValue(object, _DataObjectProperty.ProductVersionId,
                        productVersionId);
                }

                Object scopeName = null;

                scopeName = resultSet.getObject(columnIndex++);

                object.setScopeNameNull(resultSet.getBoolean(columnIndex++));

                if (scopeName != null) {
                    setBeanValue(object, _DataObjectProperty.ScopeName,
                        scopeName);
                }

                Object scopePriority = null;

                scopePriority = resultSet.getObject(columnIndex++);

                object.setScopePriorityNull(resultSet.getBoolean(columnIndex++));

                if (scopePriority != null) {
                    setBeanValue(object, _DataObjectProperty.ScopePriority,
                        scopePriority);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object productVersionName = null;

                productVersionName = resultSet.getObject(columnIndex++);

                object.setProductVersionNameNull(resultSet.getBoolean(
                        columnIndex++));

                if (productVersionName != null) {
                    setBeanValue(object,
                        _DataObjectProperty.ProductVersionName,
                        productVersionName);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
